package com.example.a2209_shop.utils

import android.content.Context
import android.util.Log
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils

/**
 * 登录拦截---全局降级策略
 */
@Interceptor(priority = 1)
class LoginInterceptor : IInterceptor {
    override fun init(context: Context?) {
        //初始化 ---可以不用重写方法
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        //处理登录拦截的策略
        //跳转到主页或者主页内的所有界面均需用户已登录  --不符合条件的，需跳转到登录界面
        if (postcard?.path.equals("/app/RegisterActivity") || postcard?.path.equals("/app/LoginActivity") || SPUtils.getInstance()
                .getString("token").isNotEmpty()
        ) {
            callback?.onContinue(postcard)
        } else {
            ARouter.getInstance().build("/app/LoginActivity").navigation()
        }


    }
}